class Solution:
    def numsSameConsecDiff(self, N: int, K: int) -> list:
        def func(N, K, n, layer, path, paths, limit):
            if layer == N:
                if path // limit > 0 or N == 1:
                    paths.append(path)
                return
            for i in range(10):
                if abs(n - i) != K:
                    continue
                func(N, K, i, layer + 1, path * 10 + i, paths, limit)

        res = []
        limit = 1
        for i in range(N - 1):
            limit *= 10
        for i in range(10):
            func(N, K, i, 1, i, res, limit)

        return res
